home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / DICLOSE.C < prev    next >
C/C++ Source or Header  |  1995-09-19  |  4KB  |  147 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    diclose.c
  5. //   Title:    Data File I/O Library
  6. //  Notice:    John M. Weeder
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //
  24. //    This module contains code to close data files.
  25. //
  26. //    The code in this module should be written entirely in C. 
  27. //    Do not use any C++ constructs.
  28. //
  29. //    This module is portable to:
  30. //        DOS 3.X+
  31. //        MS Windows 3.X+
  32. //        OS/2 2.X+
  33. //        OS/2 2.0 PM
  34. //        SCO UNIX.
  35. //
  36. //    The following compilers are supported:
  37. //        MSC 6.0A
  38. //        MSC/C++ 7.0
  39. //        Borland C++ 3.1 for DOS
  40. //        Borland C++ 1.0 for OS/2 2.X
  41. //        SCO UNIX cc
  42. //
  43. //----------------------------------------------------------------------------
  44. #include <di.h>
  45.  
  46.  
  47. //----------------------------------------------------------------------------
  48. //   Description:    Close all open files
  49. //    Parameters:    
  50. //       Returns:    TRUE if successful.
  51. //----------------------------------------------------------------------------
  52. BOOL FN_E DioCloseAll(void)
  53. {
  54.     HPF hpf;
  55.     BOOL fResult = TRUE;
  56.  
  57.     for (hpf = 0; hpf < MAX_PHYSICAL_FILES; ++hpf)
  58.         if (di.physical[hpf].fUsed && !DioClosePhysical(hpf))
  59.             fResult = FALSE;
  60.  
  61.     if (!DioSetDataPath(NULL))
  62.         fResult = FALSE;
  63.  
  64.     return fResult;
  65. }
  66.  
  67.  
  68. //----------------------------------------------------------------------------
  69. //   Description:    Close logical file
  70. //    Parameters:    hlf        Logical file handle
  71. //                                    If handle is invalid, the function returns success.
  72. //       Returns:    TRUE if successful.
  73. //----------------------------------------------------------------------------
  74. BOOL FN_E DioCloseLogical(HLF hlf)
  75. {
  76.     BOOL fResult = TRUE;
  77.  
  78.  
  79.     if (hlf < 0
  80.     || hlf >= MAX_LOGICAL_FILES
  81.     || !di.logical[hlf].fUsed)
  82.         return TRUE;
  83.  
  84.     DioCacheRelease(hlf);
  85.     if (di.logical[hlf].hlfNext >= 0)
  86.         if (!DioCloseLogical(di.logical[hlf].hlfNext))
  87.             fResult = FALSE;
  88.  
  89.     memset(&di.logical[hlf], 0, sizeof(di.logical[hlf]));
  90.     di.cLogical--;
  91.     return fResult;
  92. }
  93.  
  94.  
  95. //----------------------------------------------------------------------------
  96. //   Description:    Close physical file.
  97. //    Parameters:    hpf        Physical file handle
  98. //                                    If handle is invalid, the function returns success.
  99. //       Returns:    TRUE if successful.
  100. //----------------------------------------------------------------------------
  101. BOOL FN_E DioClosePhysical(HPF hpf)
  102. {
  103.     HLF hlf;
  104.     BOOL fResult = TRUE;
  105.  
  106.     if (hpf < 0                                    // Is file open?
  107.     || hpf >= MAX_PHYSICAL_FILES
  108.     || !di.physical[hpf].fUsed)            
  109.         return FALSE;
  110.                                                     // Close all associated logical files
  111.     for (hlf = 0; hlf < MAX_LOGICAL_FILES; ++hlf)
  112.         if (di.logical[hlf].fUsed
  113.         && di.logical[hlf].hpf == hpf
  114.         && !DioCloseLogical(hlf))
  115.             fResult = FALSE;
  116.                                                     // Close physical file
  117.     if (!FileClose(di.physical[hpf].hf))    
  118.         fResult = FALSE;
  119.  
  120.     if (di.physical[hpf].pdatadir)
  121.         MemFree(di.physical[hpf].pdatadir);
  122.     if (di.physical[hpf].pdatahdr)
  123.         MemFree(di.physical[hpf].pdatahdr);
  124.                                                     // Clear entry
  125.     memset(&di.physical[hpf], 0, sizeof(di.physical[hpf]));
  126.     di.cPhysical--;
  127.     return fResult;
  128. }
  129.  
  130.  
  131. //----------------------------------------------------------------------------
  132. //   Description:    
  133. //    Parameters:    
  134. //       Returns:    TRUE if successful.
  135. //----------------------------------------------------------------------------
  136. BOOL FN_E DioRelease(void)
  137. {
  138.     BOOL fResult = DioDirReleaseAll();
  139.  
  140.     if (DioHeaderReleaseAll())
  141.         fResult = FALSE;
  142.     return fResult;
  143. }
  144. //----------------------------------------------------------------------------
  145. //------------------------------- End of File --------------------------------
  146. //----------------------------------------------------------------------------
  147.